package com.fenghongzhang.day013;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.RemoteViews;

public class MyReceiver extends BroadcastReceiver {

    private static final String TAG = "MyReceiver";
    @Override
    public void onReceive(Context context, Intent intent) {
        Log.i(TAG, "onReceive: ");

        //通知管理者
        NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        Notification.Builder builder = new Notification.Builder(context);

        builder.setSmallIcon(R.mipmap.ic_launcher);
        builder.setContentTitle("标题");

        RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.notify_layout);

        //去往Activity
        //1, 组件id,  2,PendingIntent
        Intent intent1 = new Intent(context,MainActivity.class);
        PendingIntent activity = PendingIntent.getActivity(context, 0, intent1, 0);
        remoteViews.setOnClickPendingIntent(R.id.notify_btn,activity);


        //去往广播接收者
        Intent intent2 = new Intent();
        intent2.setAction("com.bawei.1803");
        PendingIntent broadcast = PendingIntent.getBroadcast(context, 0, intent2, 0);
        //2, 组件id .2 PendingIntent
        remoteViews.setOnClickPendingIntent(R.id.notify_broadcast,broadcast);


        builder.setCustomContentView(remoteViews); //24


        //22
//        builder.setContent(remoteViews); //22

        builder.setContentIntent(activity);
        builder.setAutoCancel(true);

        manager.notify(1,builder.build());

//        manager.cancel(1);

    }
}
